/*     */ package com.newcrm.webapi;
/*     */ 
/*     */ import com.newcrm.bean.User;
/*     */ import com.newcrm.db.CustomerFieldManager;
/*     */ import com.newcrm.db.CustomerManager;
/*     */ import com.newcrm.db.DealFieldManager;
/*     */ import com.newcrm.exception.DBException;
/*     */ import com.newcrm.exception.NotFoundException;
/*     */ import com.newcrm.util.ParameterUtil;
/*     */ import com.newcrm.util.Util;
/*     */ import com.newcrm.webapi.sub.AddUpdateCompany;
/*     */ import com.newcrm.webapi.sub.CheckCompanyNameIsExist;
/*     */ import com.newcrm.webapi.sub.CheckQQIsExist;
/*     */ import com.newcrm.webapi.sub.CheckTelIsExist;
/*     */ import com.newcrm.webapi.sub.ConfirmDestroyCustomer;
/*     */ import com.newcrm.webapi.sub.DeleteCustomer;
/*     */ import com.newcrm.webapi.sub.DeleteCustomerAvatar;
/*     */ import com.newcrm.webapi.sub.ListCustomerPermissionsChangeLog;
/*     */ import com.newcrm.webapi.sub.ListSearchEngineResult;
/*     */ import com.newcrm.webapi.sub.MergeCustomer;
/*     */ import com.newcrm.webapi.sub.ShowCompany;
/*     */ import com.newcrm.webapi.sub.ShowCompanyBusinessArchives;
/*     */ import com.newcrm.webapi.sub.ShowNewCompany;
/*     */ import com.newcrm.webapi.sub.ShowUpdateCompany;
/*     */ import com.newcrm.webapi.sub.UpdateAvatar;
/*     */ import java.io.IOException;
/*     */ import java.sql.SQLException;
/*     */ import java.util.List;
/*     */ import javax.servlet.RequestDispatcher;
/*     */ import javax.servlet.ServletConfig;
/*     */ import javax.servlet.ServletContext;
/*     */ import javax.servlet.ServletException;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import org.apache.log4j.Logger;
/*     */ 
/*     */ public class Company extends AbstractHttpServlet
/*     */ {
/*     */   private static final long serialVersionUID = -8764530014351862906L;
/*  46 */   private static Logger logger = Logger.getLogger(Company.class.getName());
/*     */ 
/*     */   public void doGet(HttpServletRequest request, HttpServletResponse response)
/*     */     throws ServletException, IOException
/*     */   {
/*  60 */     if (!checkLogin(request)) {
/*  61 */       super.showLoginPage(request, response);
/*  62 */       return;
/*     */     }
/*     */ 
/*  65 */     String url = request.getRequestURI();
/*  66 */     String[] param = ParameterUtil.getParameters(url, getTagkey());
/*     */ 
/*  68 */     if ((param != null) && (param.length == 1))
/*     */     {
/*  70 */       if ("checkCompanyName".equals(param[0])) {
/*  71 */         AbstractAction action = new CheckCompanyNameIsExist(this);
/*     */         try {
/*  73 */           action.parse(request, response);
/*     */         } catch (NotFoundException e) {
/*  75 */           request.getRequestDispatcher("/errorpage.jsp").forward(
/*  76 */             request, response);
/*     */         }
/*  78 */         return;
/*     */       }
/*     */ 
/*  82 */       if ("checkTelExist".equals(param[0])) {
/*  83 */         AbstractAction action = new CheckTelIsExist(this);
/*     */         try {
/*  85 */           action.parse(request, response);
/*     */         } catch (NotFoundException e) {
/*  87 */           request.getRequestDispatcher("/errorpage.jsp").forward(
/*  88 */             request, response);
/*     */         }
/*  90 */         return;
/*     */       }
/*     */ 
/*  93 */       if ("checkQQExist".equals(param[0])) {
/*  94 */         AbstractAction action = new CheckQQIsExist(this);
/*     */         try {
/*  96 */           action.parse(request, response);
/*     */         } catch (NotFoundException e) {
/*  98 */           request.getRequestDispatcher("/errorpage.jsp").forward(
/*  99 */             request, response);
/*     */         }
/* 101 */         return;
/*     */       }
/*     */ 
/* 105 */       if ("searchEngine".equals(param[0])) {
/* 106 */         ListSearchEngineResult action = new ListSearchEngineResult(this);
/*     */         try {
/* 108 */           action.parse(request, response);
/*     */         } catch (NotFoundException e) {
/* 110 */           request.getRequestDispatcher("/errorpage.jsp").forward(
/* 111 */             request, response);
/*     */         }
/* 113 */         return;
/*     */       }
/*     */ 
/* 117 */       if ("businessArchives".equals(param[0])) {
/* 118 */         ShowCompanyBusinessArchives action = new ShowCompanyBusinessArchives(
/* 119 */           this);
/*     */         try {
/* 121 */           action.parse(request, response);
/*     */         } catch (NotFoundException e) {
/* 123 */           request.getRequestDispatcher("/errorpage.jsp").forward(
/* 124 */             request, response);
/*     */         }
/* 126 */         return;
/*     */       }
/*     */ 
/* 130 */       if ("permissionsChange".equals(param[0])) {
/* 131 */         ListCustomerPermissionsChangeLog action = new ListCustomerPermissionsChangeLog(
/* 132 */           this);
/*     */         try {
/* 134 */           action.parse(request, response);
/*     */         } catch (NotFoundException e) {
/* 136 */           request.getRequestDispatcher("/errorpage.jsp").forward(
/* 137 */             request, response);
/*     */         }
/* 139 */         return;
/*     */       }
/*     */     }
/*     */ 
/* 143 */     if ((param != null) && (param.length == 2))
/*     */     {
/* 145 */       if ("duplicates".equals(param[1])) {
/* 146 */         int id = Util.str2Int(param[0]);
/* 147 */         request.setAttribute("id", param[0]);
/* 148 */         request.setAttribute("isPerson", "0");
/* 149 */         CustomerManager manager = new CustomerManager();
/*     */ 
/* 151 */         String customerName = manager.getName(id);
/* 152 */         if (customerName == null) {
/* 153 */           request.getRequestDispatcher("/errorpage.jsp").forward(
/* 154 */             request, response);
/* 155 */           return;
/*     */         }
/* 157 */         request.setAttribute("name", customerName);
/* 158 */         request.getRequestDispatcher("/customer_duplicates.jsp")
/* 159 */           .forward(request, response);
/* 160 */         return;
/*     */       }
/*     */ 
/* 164 */       if ("avatar".equals(param[1])) {
/* 165 */         int id = Util.str2Int(param[0]);
/* 166 */         String path = getServletConfig().getServletContext()
/* 167 */           .getRealPath("images/upload/company/");
/* 168 */         UpdateAvatar action = new UpdateAvatar(this, id, path, false);
/*     */         try {
/* 170 */           action.parse(request, response);
/*     */         } catch (NotFoundException e) {
/* 172 */           request.getRequestDispatcher("/errorpage.jsp").forward(
/* 173 */             request, response);
/*     */         }
/* 175 */         return;
/*     */       }
/*     */     }
/*     */ 
/* 179 */     if ((param != null) && (param.length == 3) && (param[0] != null) && 
/* 180 */       (param[0].length() > 0))
/*     */     {
/* 182 */       if (("avatar".equals(param[1])) && 
/* 183 */         ("delete".equals(param[2]))) {
/* 184 */         int id = Util.str2Int(param[0]);
/* 185 */         DeleteCustomerAvatar action = new DeleteCustomerAvatar(this, 
/* 186 */           id, false);
/*     */         try {
/* 188 */           action.parse(request, response);
/*     */         } catch (NotFoundException e) {
/* 190 */           request.getRequestDispatcher("/errorpage.jsp").forward(
/* 191 */             request, response);
/*     */         }
/* 193 */         return;
/*     */       }
/*     */ 
/* 196 */       if (("people".equals(param[1])) && 
/* 197 */         ("new".equals(param[2])))
/*     */       {
/* 199 */         CustomerManager manager = new CustomerManager();
/* 200 */         CustomerFieldManager customerFieldManager = new CustomerFieldManager();
/* 201 */         User user = super.getLoginUser(request);
/* 202 */         int id = Util.str2Int(param[0]);
/*     */ 
/* 204 */         String customerName = manager.getName(id);
/* 205 */         if (customerName != null) {
/* 206 */           request.setAttribute("companyId", param[0]);
/* 207 */           request.setAttribute("companyName", customerName);
/*     */         }
/* 209 */         List fields = customerFieldManager.list(
/* 210 */           user.companyId, 2);
/* 211 */         request.setAttribute("fields", fields);
/*     */ 
/* 213 */         request.getRequestDispatcher("/people_new.jsp").forward(
/* 214 */           request, response);
/* 215 */         return;
/*     */       }
/*     */ 
/* 219 */       if (("deals".equals(param[1])) && ("new".equals(param[2]))) {
/* 220 */         CustomerManager manager = new CustomerManager();
/* 221 */         int id = Util.str2Int(param[0]);
/* 222 */         String customerName = manager.getName(id);
/* 223 */         if (customerName != null) {
/* 224 */           request.setAttribute("customerId", param[0]);
/* 225 */           request.setAttribute("customerName", customerName);
/* 226 */           request.setAttribute("customerType", Integer.valueOf(0));
/*     */         }
/*     */ 
/* 229 */         DealFieldManager dealFieldManager = new DealFieldManager();
/* 230 */         User user = super.getLoginUser(request);
/*     */         try {
/* 232 */           List fields = dealFieldManager
/* 233 */             .list(user.companyId);
/* 234 */           request.setAttribute("fields", fields);
/*     */         } catch (DBException e) {
/* 236 */           logger.warn("get deal customer filed info failed", e);
/*     */         } catch (SQLException e) {
/* 238 */           logger.warn("get deal customer filed info failed", e);
/*     */         }
/*     */ 
/* 241 */         request.getRequestDispatcher("/deal_new.jsp").forward(request, 
/* 242 */           response);
/* 243 */         return;
/*     */       }
/*     */ 
/* 247 */       if ("duplicates".equals(param[1])) {
/* 248 */         int oldId = Util.str2Int(param[0]);
/* 249 */         int newId = Util.str2Int(param[2]);
/*     */ 
/* 251 */         MergeCustomer action = new MergeCustomer(this, oldId, newId, 
/* 252 */           false);
/*     */         try {
/* 254 */           action.parse(request, response);
/*     */         } catch (NotFoundException e) {
/* 256 */           request.getRequestDispatcher("/errorpage.jsp").forward(
/* 257 */             request, response);
/*     */         }
/* 259 */         return;
/*     */       }
/*     */     }
/*     */ 
/* 263 */     super.doGet(request, response);
/*     */   }
/*     */ 
/*     */   protected AbstractAction getAddAction()
/*     */   {
/* 268 */     return new AddUpdateCompany(this, null, getServletConfig()
/* 269 */       .getServletContext().getRealPath("lucene/"));
/*     */   }
/*     */ 
/*     */   protected AbstractAction getDeleteAction(String id)
/*     */   {
/* 274 */     return new DeleteCustomer(this, id, getServletConfig()
/* 275 */       .getServletContext().getRealPath("lucene/"));
/*     */   }
/*     */ 
/*     */   protected String getTagkey()
/*     */   {
/* 280 */     return "/company";
/*     */   }
/*     */ 
/*     */   protected AbstractAction getUpdateAction(String id)
/*     */   {
/* 285 */     return new AddUpdateCompany(this, id, getServletConfig()
/* 286 */       .getServletContext().getRealPath("lucene/"));
/*     */   }
/*     */ 
/*     */   protected AbstractAction getShowAddPageAction()
/*     */   {
/* 291 */     return new ShowNewCompany(this);
/*     */   }
/*     */ 
/*     */   protected AbstractAction getShowAction(String id)
/*     */   {
/* 296 */     return new ShowCompany(this, id);
/*     */   }
/*     */ 
/*     */   protected AbstractAction getShowUpdatePageAction(String id)
/*     */   {
/* 301 */     return new ShowUpdateCompany(this, id);
/*     */   }
/*     */ 
/*     */   protected AbstractAction getListAction()
/*     */   {
/* 306 */     return null;
/*     */   }
/*     */ 
/*     */   protected AbstractAction getShowConfirmDestroyAction(String id)
/*     */   {
/* 311 */     return new ConfirmDestroyCustomer(this, id, false);
/*     */   }
/*     */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.webapi.Company
 * JD-Core Version:    0.6.1
 */